<?php
 namespace app\admin\controller;
 use app\admin\model;
 use think\Db;
 use think\Request;
 /*
 *
 */
 class Login extends \think\Controller{
 	public function login(){
 		$acc = session('loginInfo','','admin');
 		if($acc){
			return $this->redirect('index/index'); 
 		}else{
 		 	return $this->fetch();
 		}
 	}
 	public function dologin(){		
 		$validate = validate('Admin');
 		if(!$validate->scene('login')->check(input('post.'))){
 			$this->error($validate->getError());
 		}

 		$user['uname'] = input("post.uname");
 		$user['pwd'] = md5(input("post.pwd"));
 		//$res = Db::table('lot_admin')->where('uname',$uname)->find();
 		$res = model('Admin')->where($user)->find();
 		if($res){				
 					//'admin' 是作用域
			session('loginInfo',$res,'admin');
			return $this->success('登录成功','index/index');				
 		}else{
 			return $this->error('用户名或密码错误');
 		}
 	}
 	public function dologout(){
 			session(null,'admin');
 			$this->success("注销成功",'login/login');
 	}
 }